﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace mpsalaryprojectgroup
{
    public partial class NEWDelete : System.Web.UI.Page
    {

     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Usename"] != null)
                {
                    String username = (string)(Session["Usename"]);
                    if (username == null)
                    {
                        Response.Redirect("NEWMainPage.aspx");
                    }
                    else
                    {
                        lblUsername.Text = username;
                        lblName.Text = username;
                        //String passwordLogin = (string)(Session["Password"]);
                        mpsalary.App_Code.User user1 = new mpsalary.App_Code.User();
                        user1.Usename = username;
                        user1.RetrieveUserInfo(username);

                        lblSalutation.Text = user1.Salutation;
                        lblSchoolRetrieve.Text = user1.School;
                        lblEmail.Text = user1.Email;
                        //lblPassword.Text = user1.Password;
                        lblCompanyRetrieve.Text = user1.Company;
                        lblFirstName.Text = user1.FirstName;
                        lblLastName.Text = user1.LastName;
                        lblMobileNo.Text = user1.MobileNo;
                        lblNRIC.Text = user1.NRIC;
                        lblOccupation.Text = user1.Occupation;
                        if (lblOccupation.Text.Equals("Employer"))
                        {
                            lblSchool.Visible = false;
                            lblSchoolRetrieve.Visible = false;

                        }
                        if (lblOccupation.Text.Equals("Student"))
                        {
                            lblCompany.Visible = false;
                            lblCompanyRetrieve.Visible = false;

                        }
                        if (lblOccupation.Text.Equals("Others"))
                        {
                            lblSchool.Visible = false;
                            lblSchoolRetrieve.Visible = false;
                            lblCompany.Visible = false;
                            lblCompanyRetrieve.Visible = false;

                        }
                        lblDOB.Text = user1.DOB;
                    }
                }
                else if (Session["UsenameLogin"] != null)
                {
                   String loginName = (string)(Session["UsenameLogin"]);
                    if (loginName == null)
                    {
                        Response.Redirect("NEWMainPage.aspx");
                    }
                    else
                    {
                        lblUsername.Text = loginName;
                        lblName.Text = loginName;
                        //String passwordLogin = (string)(Session["Password"]);
                        mpsalary.App_Code.User user1 = new mpsalary.App_Code.User();
                        user1.Usename = loginName;
                        user1.RetrieveUserInfo(loginName);
                        
                        lblSalutation.Text = user1.Salutation;
                        lblSchoolRetrieve.Text = user1.School;
                        lblEmail.Text = user1.Email;
                        //lblPassword.Text = user1.Password;
                        lblCompanyRetrieve.Text = user1.Company;
                        lblFirstName.Text = user1.FirstName;
                        lblLastName.Text = user1.LastName;
                        lblMobileNo.Text = user1.MobileNo;
                        lblNRIC.Text = user1.NRIC;
                        lblOccupation.Text = user1.Occupation;
                        if(lblOccupation.Text.Equals("Employer"))
                        {
                            lblSchool.Visible = false;
                            lblSchoolRetrieve.Visible = false;

                        }
                        if (lblOccupation.Text.Equals("Student"))
                        {
                            lblCompany.Visible = false;
                            lblCompanyRetrieve.Visible = false;

                        }
                        if (lblOccupation.Text.Equals("Others"))
                        {
                            lblSchool.Visible = false;
                            lblSchoolRetrieve.Visible = false;
                            lblCompany.Visible = false;
                            lblCompanyRetrieve.Visible = false;

                        }
                        lblDOB.Text = user1.DOB;
                    }
                }
            else
            {
                Response.Redirect("NEWMainPage.aspx");
               
            }
        }
            DisableBufferingOnPage();
    }

        protected void DisableBufferingOnPage()
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            // set expiry date in the past
            Response.Expires = -1;
            Response.CacheControl = "no-cache";
            Response.Cache.SetNoStore();
            Response.AppendHeader("Pragma", "no-cache");
            Response.AppendHeader("Cache-Control", "no-cache");
            Response.CacheControl = "no-cache";
            Response.Expires = -1;
            Response.ExpiresAbsolute = new DateTime(1900, 1, 1);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }

       

        protected void btnDelete_Click(object sender, EventArgs e)
        {

            mpsalary.App_Code.User u = new mpsalary.App_Code.User();
            u.Usename = lblUsername.Text;
            u.DeleteUser();
            Response.Redirect("NEWMainPage.aspx");
        }
    }
}